﻿using MathTutorPro.DAL;
using MathTutorPro.Data.Entities;
using Microsoft.EntityFrameworkCore;

namespace MathTutorPro.Data.DAL
{
    public class ClassDal
    {
        private readonly AppDbContext _context;
        public ClassDal(AppDbContext context)
        {
            _context = context;
        }
        public async Task<IEnumerable<Class>> GetClassByUserAsync(string teacherId)
        {
            return await _context.Class
                .Where(c => c.TeacherId == teacherId)
                .Include(c => c.ClassDetails)
                .ToListAsync();
        }
        public async Task<Class> CreateAsync(Class newClass)
        {
            _context.Class.Add(newClass);
            await _context.SaveChangesAsync();
            return newClass;
        }
        public async Task<bool> ExistsAsync(int classId, string teacherId)
        {
            return await _context.Class
                .AnyAsync(c => c.Id == classId && c.TeacherId == teacherId);
        }
        public async Task<List<string>> GetClassStudentIdsAsync(int classId)
        {
            return await _context.ClassDetail
                .Where(cd => cd.ClassId == classId)
                .Select(cd => cd.UserId)
                .ToListAsync();
        }
    }
}
